<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Index extends WxHomeController {

	function __construct() {
		parent::__construct();
		$this -> sidebar = "Index";
		$this -> load ->model("Admin_model");
        $this->load->model("Announcement_model");
        $this->load->model('Student_feedback_model');
        $this->load->model('Student_feedback_record_model');
        $this->load->model('Supervisor_feedback_model');
        $this->load->model('Supervisor_feedback_record_model'); 
	}

	function Index($login_role=0) {
		// $data['login_role']=$login_role;
		$result = $this ->Admin_model->get_single(array("id"=>$_SESSION[SESS_USER_HOME]['id']));
		// $data['sub_role']=explode(",",$result['sub_role_id']);
		$data['detail']=$result;
        unset($_SESSION[SESS_ASSESS]);
		$this->load->view('home/index',$data);
	}

    //信息反馈
    function Back(){
        $this->load->view('home/back');
    }
    //课堂教学评价
    function evaluation(){        
		$role=explode(',',$_SESSION[SESS_USER_HOME]['sub_role_id']);
		array_push($role, $_SESSION[SESS_USER_HOME]['role_id']);	
		$data['role']=array_merge(array_filter($role));	
        
        unset($_SESSION[SESS_ASSESS]);
        $this->load->view('home/evaluation',$data);
    }
    //其他材料提交
    function others(){
        $this->load->view('home/others');
    }


	function Broadcast(){
        // $title=$this->Announcement_model->query("select *  from db_announcement ");
        $sub_role=explode(",", $_SESSION[SESS_USER_HOME]['sub_role_id']);
        array_push($sub_role,$_SESSION[SESS_USER_HOME]['role_id']);
        $connar['where']=$this -> sqlEscape('status=?? and start<=?? and end >=??',array(CommonStatus::UnDeleted[XPHEnum::Value],time(),time()));
        foreach ($sub_role as $k => $v) {
        	if($k==0){
        		$connar['where'].=$this->sqlEscape(" and (find_in_set(??,role_id_str)!=0 ",array($v));
        	}else{
        		$connar['where'].=$this->sqlEscape(" or find_in_set(??,role_id_str)!=0 ",array($v));
        	}        	
        }
        $connar['where'].=")";
        $title=$this -> Announcement_model->get_list_full($connar);
        exit(retJson('获取标题', true,$title));        
    }   

    // 判断是否有待处理反馈
    function checkFeedback(){
        $role=explode(',',$_SESSION[SESS_USER_HOME]['sub_role_id']);
        array_push($role,$_SESSION[SESS_USER_HOME]['role_id']);
        $data= array();
       if(in_array(WebRole::Manage[XPHEnum::Value],$role)){
            $data['feedbackcount']=$this->Supervisor_feedback_model->query('select count(*)as count from(select * from db_student_feedback union all select * from db_supervisor_feedback) feedback where role_belong='.WebRole::Manage[XPHEnum::Value].' and status='.FeedBackStatus::ToAudit[XPHEnum::Value].' and belong=0 and del_flag='.CommonStatus::UnDeleted[XPHEnum::Value])[0]['count'];
            $data['feedbackcountTeacher']=$this->Supervisor_feedback_model->query('select count(*)as count from(select * from db_student_feedback union all select * from db_supervisor_feedback) feedback where role_belong='.WebRole::Manage[XPHEnum::Value].' and status='.FeedBackStatus::ToAudit[XPHEnum::Value].' and belong='.$_SESSION[SESS_USER_HOME]['id'].' and del_flag='.CommonStatus::UnDeleted[XPHEnum::Value])[0]['count'];
        }else if(in_array(WebRole::UnitSupervisorGroupLeader[XPHEnum::Value],$role)){
            $data['feedbackcount']=$this->Supervisor_feedback_model->query('select count(*)as count from(select * from db_student_feedback union all select * from db_supervisor_feedback) feedback LEFT JOIN db_admin a1 on a1.id=feedback.creator where feedback.status='.FeedBackStatus::ToAudit[XPHEnum::Value].' and a1.dept_name="'.$_SESSION[SESS_USER_HOME]['dept_name'].'" and role_belong='.WebRole::UnitSupervisorGroupLeader[XPHEnum::Value].' and del_flag='.CommonStatus::UnDeleted[XPHEnum::Value].' and belong=0')[0]['count'];
            $data['feedbackcountTeacher']=$this->Supervisor_feedback_model->query('select count(*)as count from(select * from db_student_feedback union all select * from db_supervisor_feedback) feedback LEFT JOIN db_admin a1 on a1.id=feedback.creator where feedback.status='.FeedBackStatus::ToAudit[XPHEnum::Value].' and a1.dept_name="'.$_SESSION[SESS_USER_HOME]['dept_name'].'" and role_belong='.WebRole::UnitSupervisorGroupLeader[XPHEnum::Value].' and del_flag='.CommonStatus::UnDeleted[XPHEnum::Value].' and belong='.$_SESSION[SESS_USER_HOME]['id'])[0]['count'];
        }
        exit(retJson('反馈',true,$data));
    }
}
